package ym.ecrm.core.common.util;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 分布对象，包含当前页数据、当前页码、每页的记录数、总记录数
 * 
 * @author Princess
 * 
 * @param <T>
 */
public class Pager<T> {

	private static int DEFAULT_PAGE_SIZE = 20;

	private int pageNumber;
	private int pageSize = DEFAULT_PAGE_SIZE;
	private Long totalCount;
	private List<T> data;

	public Pager() {
		this(0, DEFAULT_PAGE_SIZE, 0l, new ArrayList<T>());
	}

	public Pager(int pageNumber, int pageSize, Long totalCount, List<T> data) {
		this.pageNumber = pageNumber;
		this.pageSize = pageSize;
		this.totalCount = totalCount;
		this.data = data;
	}

	public static int getStartIndex(int pageNumber, int pageSize) {
		if (pageNumber < 1) {
			return 0;
		} else {
			return (pageNumber - 1) * pageSize;
		}

	}

	public int getPageNumber() {
		return pageNumber;
	}

	public void setPageNumber(int pageNumber) {
		this.pageNumber = pageNumber;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public Long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public boolean isEmpty() {
		if (data.isEmpty()) {
			return true;
		} else {
			return false;
		}
	}

	// 取总页数
	public long getTotalPageCount() {
		if (totalCount % pageSize == 0)
			return totalCount / pageSize;
		else
			return totalCount / pageSize + 1;
	}
}
